Monday, November 23, 2020

White Box Testing

White Box Testing

  • White-box testing sometimes called glass-box testing.
  • It is a test-case design philosophy that uses the control structure described as part of the component-level design to derive test cases.
  • Using white-box testing methods, you can derive test cases that
    • (1) Guarantee that all independent paths within a module have been exercised at least once,
    • (2) Exercise all logical decisions on their true and false sides,
    • (3) Execute all loops at their boundaries and within their operational bounds,
    • (4) Exercise internal data structures to ensure their validity.
  • White-box testing is a verification technique software engineers can use to examine if their code works as expected.
  • White box testing is a strategy in which testing is based on:
    • the internal paths,
    • structure, and
    • implementation of the software under test (SUT).
  • White-box testing is also known as structural testing, clear box testing, and glass box testing. 
  • Generally requires detailed programming skills.

White Box Testing Techniques

  • Basis path testing
    • Flow graph notation
    • Cyclomatic complexity
    • Derived test cases
    • Graph metrics
  • Control structure testing
    • Condition testing
    • Data Flow testing
    • Loop testing 

  • Basis path testing
    • Basis path testing is a white-box testing technique
    • The basis path method enables the test-case designer to derive a logical complexity measure of a procedural design and use this measure as a guide for defining a basis set of execution paths
(1) Flow Graph Notation
    • A simple notation for the representation of control flow, called a flow graph (or program graph).
  • The flow graph describes logical control flow using the notation illustrated in Figure.
Flow Graph Notation

(2) Independent Program Path
    • in terms of a flow graph, an independent path must move along at least one edge that has not been traversed before the path is defined.
    • For example, a set of independent paths for the flow graph illustrated in Figure as…
    • Path 1: 1-11
    • Path 2: 1-2-3-4-5-10-1-11
    • Path 3: 1-2-3-6-8-9-10-1-11
    • Path 4: 1-2-3-6-7-9-10-1-11
  • How do you know how many paths to look for? The computation of cyclomatic complexity provides the answer
  • Cyclomatic complexity is a software metric that provides a quantitative measure of the logical complexity of a program..
  • When used in the context of the basis path testing method, the value computed for cyclomatic complexity defines
  • The number of independent paths in the basis set of a program.
  • Provides you with an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at least once.
  • How Is Cyclomatic Complexity Computed?
  • (1) The number of regions of the flow graph corresponds to the cyclomatic complexity.
    • The flow graph has 4 regions
  • (2) V(G) = E – N + 2
    • E : Number of flow graph edges 
    • N : Number of flow graph nodes
    • V(G) = 11 edges – 9 nodes + 2 = 4
  • (3) V(G) = P + 1
    • P : Number of predicate nodes [More than one outcomes]
    • V(G) = 3 predicate nodes + 1 = 4
(3) Deriving Test Cases
  • The basis path testing method can be applied to a procedural design or to source code
  • The following steps can be applied to derive the basis set / Test cases …
    • Using the design or code as a foundation, draw a corresponding flow graph.
    • Determine the cyclomatic complexity of the resultant flow graph.
    • Determine a basis set of linearly independent paths
    • Prepare test cases that will force the execution of each path in the basis set.
(4) Graph Matrices
  • A data structure, called a graph matrix, can be quite useful for developing a software tool that assists in basis path testing.
  • Graph matrix is a square matrix whose size (i.e., number of rows and columns) is equal to the number of nodes on the flow graph.
  • Each row and column corresponds to an identified node, and matrix entries correspond to connections (an edge) between nodes.
  • A simple example of a flow graph and its corresponding graph matrix [Bei90] is shown in Figure…
Graph Matrices

Control Structure testing technique

(1) Condition Testing
  • Condition testing [Tai89] is a test-case design method that exercises the logical conditions contained in a program module. 
  • A simple condition is a Boolean variable or a relational expression.
Condition Testing

    
(2) Control flow testing

Control flow testing

(3) Data Flow Testing
  • Data flow testing is a powerful tool to detect improper use of data values due to coding errors.
  • For example : main() { int x; if (x == 42 ){ ...} }
  • Variables that contain data values have a defined life cycle.
  • They are created, they are used, and they are killed (destroyed) – Scope

Data Flow Testing

(4) Loop Testing
  • Loop testing is a white-box testing technique that focuses exclusively on the validity of loop constructs.
  • Four different classes of loops [Bei90] can be defined:
    • Simple loops,
    • Concatenated loops,
    • Nested loops,
    • Unstructured loops

Loop Testing

White Box Testing Advantage & Disadvantages

  • Advantage
    • The tester can be sure that every path through the software under test has been identified and tested.
    • Find errors on code level.
    • Typically based on a very systematic approach, covering the complete internal module structure
  • Disadvantages
    • (1) The number of execution paths may be so large then they cannot all be tested.
    • (2) The test cases chosen may not detect data sensitivity errors.
      • For example, p=q/r; may execute correctly except when r=0.
    • (3) White box testing assumes the control flow is correct (or very close to correct). Since the tests are based on the existing paths, nonexistent paths cannot be discovered through white box testing.
    • (4) the tester must have the programming skills to understand and evaluate the software under test.

No comments:

Post a Comment